﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace Util
{
    public class RequestHelper
    {
        private static readonly HttpClient _httpClient = new HttpClient();
        public static async Task<string> GetRequest(string url, string token = "")
        {
            var request = new HttpRequestMessage(HttpMethod.Get, url);
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 
            if (!string.IsNullOrEmpty(token))
            {
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
            }
            
            var response = await _httpClient.SendAsync(request);
            response.EnsureSuccessStatusCode(); 
            var bytes = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
            var str= Encoding.UTF8.GetString(bytes);
      
            return str;
            //return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
        }

    } 
    
}
